package net.zjitc.servlet;

import net.zjitc.domain.Book;
import net.zjitc.service.BookService;
import net.zjitc.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/9.
 */
@WebServlet(name = "PurchaseServlet",urlPatterns = "/purchaseServlet")
public class PurchaseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获得id,通过id查找到图书
        String id=request.getParameter("id");
        BookService service=new BookServiceImpl();
        //没有findByID  这代码要加    Book book=service.findByID(id);
        //将书放到购物车里面
        //获得session
        HttpSession session=request.getSession(true);
        //从session里面拿到购物车对象
        List<Book> cart=null;
        cart=(List<Book>)session.getAttribute("cart");
        if (cart == null){
            cart = new ArrayList<>();
            session.setAttribute("cart",cart);
        }
      //  cart.add(book);
    }
}
